package com.xh.audit.controller.project;

import com.xh.audit.entity.project.RectificationReport;
import com.xh.audit.service.RectificationReportService;
import com.xh.common.R;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 审计问题整改报告 前端控制器
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/rectification-report")
@RequiredArgsConstructor
@Validated
public class RectificationReportController {

    private final RectificationReportService rectificationReportService;

    @PostMapping("/save")
    public R<RectificationReport> save(@RequestBody
                                       @Validated
                                       RectificationReport tosave) {
        boolean saveFlag = rectificationReportService.saveOrUpdate(tosave);
        if (saveFlag) {
            return R.success(rectificationReportService.getById(tosave.getId()));
        }
        return R.failed("保存失败");
    }

    @PostMapping("/info/{id}")
    public R<RectificationReport> info(@PathVariable
                                       @Validated
                                       @NotNull(message = "id不能空")
                                       Integer id) {

        RectificationReport byId = rectificationReportService.getById(id);
        return R.success(byId);
    }
}
